﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ImportTask.aspx.cs" Inherits="QuerySelectionLabelingTool.ImportTask" %>
<%@ Register src="AddExtractorControl.ascx" tagname="AddExtractorControl" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <style type="text/css">
        .style4
        {
        }
        .style5
        {
            width: 139px;
        }
        .style6
        {
            height: 32px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
    function test() {
        alert("hello");
    }
    function AddFactoryControl() {
        var factoryControlCount = document.getElementById("hiddenFieldFactoryControlCount").value;
        var addFactoryControlPlace = document.getElementById("addFactoryControlPlace");

        var addPlace = document.createElement("p");
        addFactoryControlPlace.appendChild(addPlace);
        var factoryFileID = "factoryControlFile" + factoryControlCount;

        var factoryAddFactoryFileID = "factoryControlAddFile" + factoryControlCount;
        var factoryAddFileHidden = "factoryAddFileHidden" + factoryControlCount;
        var factoryAddFilePlaceID = "factoryAddFilePlace" + factoryControlCount;

        var factoryGetClassID = "factoryControlGetClass" + factoryControlCount;
        var factorySelectID = "factoryControlSelect" + factoryControlCount;
        
        var factoryAddExtractorID = "factoryControlAddExtractor" + factoryControlCount;
        var factoryExtractorHidden = "factoryControlExtractorHidden" + factoryControlCount;
        var factoryAddExtractorPlaceID = "factoryControlAddExtractorPlace" + factoryControlCount;
        var factoryAddExtractorRowSpanID = "factoryAddExtractorRowSpanID" + factoryControlCount;

        addPlace.innerHTML = '<table style="border-style: groove; width:100%;" border="1" rules="all"> \
                                                <tr> \
                                                    <td align="center" style="width:17%"> \
                                                    Experiments DLL</td> \
                                                    <td> \
                                                        <div><input id="' + factoryFileID + '" name="' + factoryFileID + '" type="file" name="filefile"/>\
                                                        </div>\
                                                        </td> \
                                                </tr> \
                                                <tr>\
                                                <td align="center">Dependent Files</td>\
                                                <td><p id="' + factoryAddFilePlaceID + '"></p>\
                                                <div align="right"><input type="button" onclick="AddFactoryFile(' + factoryControlCount + ')" value="Add"/></div>\
                                                <input type="hidden" value="0" id="' + factoryAddFileHidden + '" name="' + factoryAddFileHidden + '"/>\
                                                </td>\
                                                </tr>\
                                                <tr> \
                                                    <td align="center"> \
                                                    Factory Class Type</td> \
                                                    <td> \
                                                        <input type="text" id="' + factorySelectID + '" name="' + factorySelectID + '" style="width:100%"> \
                                                        </input> \
                                                        </td> \
                                                </tr> \
                                                <tr><td align="center" id="' + factoryAddExtractorRowSpanID + '" >Extractors</td>\
                                                <td>\
                                                <p id="' + factoryAddExtractorPlaceID + '"></p>\
                                                <input type="hidden" id="' + factoryExtractorHidden + '" value="0" name="' + factoryExtractorHidden + '"/>\
                                                <div align="right"><input id="' + factoryAddExtractorID + '" type="button" value="Add" onclick="AddExtractorControl(' + factoryControlCount + ')"/></div>\
                                                </td>\
                                                </tr>\
                                                </table>';
        ++(document.getElementById("hiddenFieldFactoryControlCount").value);
    }
    //produce id is "extractor"+"id" + "name" + "addExtractorHidden.value"
    function AddExtractorControl(id) {
        var addPlaceID = "factoryControlAddExtractorPlace" + id;
        var addExtractorHidden = document.getElementById("factoryControlExtractorHidden" + id);
        var addExtractorControlPlace = document.getElementById(addPlaceID);
        var addPlace = document.createElement("p");
        addExtractorControlPlace.appendChild(addPlace);

        var extractorConfigID = "extractor" + id + "Config" + addExtractorHidden.value;
        var extractorConfigTextID = "extractor" + id + "ConfigText" + addExtractorHidden.value;
        var extractorAppendixID = "extractor" + id + "Appendix" + addExtractorHidden.value;
        var extractorRadioID = "extractor" + id + "radio" + addExtractorHidden.value;
        var extractorRadioHiddenID = "extractor" + id + "RadioHidden" + addExtractorHidden.value;
        addPlace.innerHTML = '<table border="1" rules="all" style="border-style: groove; width: 100%;">\
                                    <tr>\
                                        <td align="center" style="width:20%">\
                                        <input id="" type="radio" name="' + extractorRadioID + '" onclick="chooseConfigFileType(\'' + extractorConfigID + '\',\'' + extractorConfigTextID + '\',\'' + extractorRadioHiddenID + '\',0)" checked="checked"/>Import Config From File<br/>\
                                        <input id="" type="radio" name="' + extractorRadioID + '" onclick="chooseConfigFileType(\'' + extractorConfigID + '\',\'' + extractorConfigTextID + '\',\'' + extractorRadioHiddenID + '\',1)"/>Import Config From Database\
                                        <input id="' + extractorRadioHiddenID + '" type="hidden" name="' + extractorRadioHiddenID + '" value="0"/>\
                                            </td>\
                                        <td>\
                                            <input id="' + extractorConfigID + '" type="file" name="' + extractorConfigID + '"/>\
                                            <input id="'+extractorConfigTextID+'" type="text" name="'+extractorConfigTextID+'" style="display:none"/>\
                                            </td>\
                                        <td align="center" style="width:10%">\
                                            Appendix</td>\
                                        <td>\
                                            <input id="' + extractorAppendixID + '" type="text" name="' + extractorAppendixID + '"/></td>\
                                    </tr>\
                                </table>'
        ++(addExtractorHidden.value);
    }
    function AddFactoryFile(id) {
        var addPlaceID = "factoryAddFilePlace" + id;
        var addFileHidden = document.getElementById("factoryAddFileHidden" + id);

        var addFilePlace = document.getElementById(addPlaceID);
        var addPlace = document.createElement("p");

        var fileID = "factory" + id + "FactoryFile" + addFileHidden.value;
        addFilePlace.appendChild(addPlace);
        addPlace.innerHTML = '<div><input type="file" id="'+fileID+'" name="'+fileID+'"/></div>'
        ++(addFileHidden.value);
//        alert(fileID);
        //alert(id);
    }
    function GetFactoryClassType(fileID) {
        alert(fileID);
    }
    function chooseCreateFileType(value) {
        //alert(id);
        var fileUploadXMLFile = document.getElementById("importFileTR");
        var tableIntegrate = document.getElementById("tableIntegrate");
        var factoryControls = document.getElementById("factoryControls");
        var radioHiddenFieldXMLOrInte = document.getElementById("radioHiddenFieldXMLOrInte");
        if (value == 0) {
            radioHiddenFieldXMLOrInte.value = 0;
            tableIntegrate.style.display = "none";
            factoryControls.style.display = "none";
            fileUploadXMLFile.style.display = "block";
        }
        else {
            radioHiddenFieldXMLOrInte.value = 1;
            tableIntegrate.style.display = "block";
            factoryControls.style.display = "block";
            fileUploadXMLFile.style.display = "none";
        }
    }
    function chooseConfigFileType(browseFileID, textID, radioHiddenID,value) {
        var browseFile = document.getElementById(browseFileID);
        var text = document.getElementById(textID);
        var extractorRadioHiddenID = document.getElementById(radioHiddenID);
        if (value == 0) {
            extractorRadioHiddenID.value = 0;
            browseFile.style.display = "block";
            text.style.display = "none";
        }
        else {
            extractorRadioHiddenID.value = 1;
            browseFile.style.display = "none";
            text.style.display = "block";
        }
    }
</script>

<script type="text/javascript">
    function clickAddFactoryDLL() {
        var hid = document.getElementById("hiddenFieldIsClickAddFactory");
        hid.value = 1;
    }
</script>

        <table style="border-width: 1px; border-style: groove; width:100%;" rules="all">
            <tr>
                <td class="style5" align="center">
        Task Name</td>
                <td align="left">
        <asp:TextBox ID="TextBoxTaskName" runat="server" Width="750px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td align="center" class="style5">
                    Type</td>
                <td>
                    <input id="Radio2" type="radio" name="createFileType" value="1" onclick="chooseCreateFileType(1)" checked="checked"/>Integrate&nbsp;&nbsp;
                    <input id="Radio1" type="radio" name="createFileType" value="0"  onclick="chooseCreateFileType(0)"/>Import XML
<asp:HiddenField 
                        ID="radioHiddenFieldXMLOrInte" runat="server" ClientIDMode="Static" 
                        Value="1" />
                </td>
            </tr>
            <tr style="display : none" id="importFileTR">
                <td class="style5" align="center">
                    Import File</td>
                <td>
                 <asp:FileUpload ID="FileUploadXMLFile" runat="server" ClientIDMode="Static"/>
                </td>
            </tr>
            <tr>
                <td class="style5" align="center">
                    Judger</td>
                <td>
                    <asp:TextBox ID="TextBoxUsernames" runat="server" Width="750px"></asp:TextBox>
                </td>
            </tr>
            </table>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
                    </asp:ScriptManager>
        <br />
        <table border="1" rules="all" style="border-style: groove; width: 100%;" id="tableIntegrate">
            <tr>
                <td class="style4">
                    SQL Connection String</td>
                <td>
                    <asp:TextBox ID="textBoxConnString" runat="server" Width="750px">server=lsstc259;database=NewsClassifierFreshMeasurement;uid =freshnessReader;pwd=@freshnessReader@</asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style6" align="center">
                    Get News Query<br />
                    &nbsp;</td>
                <td class="style6">
                    <div>
                    <asp:RadioButtonList ID="radioButtonListGetNewsMethod" runat="server" 
                        RepeatDirection="Horizontal" Width="253px">
                        <asp:ListItem Value="ByKey" Selected="True">Full Text</asp:ListItem>
                        <asp:ListItem Value="TopN">Top N</asp:ListItem>
                    </asp:RadioButtonList>
                        Group ID <asp:TextBox ID="textBoxGroupID" runat="server" Width="136px"></asp:TextBox>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Key Word <asp:TextBox ID="textBoxGetNewsString" runat="server" Width="217px"></asp:TextBox>
                    <asp:Button ID="buttonGetNews" runat="server" Text="Search" 
                        onclick="buttonGetNews_Click" />
                    </div>
                </td>
            </tr>
            </table>

                    <asp:GridView ID="gridViewNewsByKey" runat="server" 
                        DataSourceID="SqlDataSourceGetNews" AllowPaging="True" 
                        AutoGenerateColumns="False" DataKeyNames="ID" 
        Width="100%">
                        <Columns>
                            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                                ReadOnly="True" SortExpression="ID" >
                             <ItemStyle HorizontalAlign="Center" />
                             </asp:BoundField>
                            <asp:BoundField DataField="SourceID" HeaderText="Source ID" 
                                SortExpression="SourceID" >
                             <ItemStyle HorizontalAlign="Center" />
                             </asp:BoundField>
                            <asp:HyperLinkField DataNavigateUrlFields="Link" 
                                DataNavigateUrlFormatString="{0}" DataTextField="Title" HeaderText="Title" 
                                Target="_blank">
                            <ItemStyle HorizontalAlign="Center" />
                            </asp:HyperLinkField>
                            <asp:BoundField DataField="CrawlTime" HeaderText="Crawl Time" 
                                SortExpression="CrawlTime" >
                             <ItemStyle HorizontalAlign="Center" />
                             </asp:BoundField>
                            <asp:BoundField DataField="PubDate" HeaderText="Publish Date" 
                                SortExpression="PubDate" >
                             <ItemStyle HorizontalAlign="Center" />
                             </asp:BoundField>
                            <asp:BoundField DataField="Description" HeaderText="Description" 
                                SortExpression="Description" >
                             <ItemStyle HorizontalAlign="Center" />
                             </asp:BoundField>
                             <asp:TemplateField  HeaderText="Add News">
                                <ItemTemplate>
                                    <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged"
                                        Checked='True' ondatabinding="CheckBox1_DataBinding"/>
                                </ItemTemplate>                    
                                 <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                    <asp:SqlDataSource ID="SqlDataSourceGetNews" runat="server" 
                        
                        ConnectionString="<%$ ConnectionStrings:NewsClassifierFreshMeasurementConnectionString %>" 
                        SelectCommand="SELECT TOP 0 ID, SourceID, Title, CrawlTime, PubDate, Link, Description, MD5Code, SourceType FROM NewsItemList">
                    </asp:SqlDataSource>

        <br />
        <div id="factoryControls">
        <p id="addFactoryControlPlace"></p>
        <div align="right">
        <input id="addFactoryControl" type="button" value="Add Factory DLL" onclick="AddFactoryControl()"/>
        <asp:HiddenField ID="hiddenFieldFactoryControlCount" runat="server"  ClientIDMode="Static" Value="0"/></div>
        </div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                    <asp:Label ID="labelMsg" runat="server"></asp:Label>
            </ContentTemplate>
                    </asp:UpdatePanel>
                    <div align="right">
           <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
            Text="Create Task" /></div>
                </asp:Content>
